home *** CD-ROM | disk | FTP | other *** search
- /*
- YRSTSUP.C
- ShareNet Local Archive Utility Support Procedures
- V4.42 02/07/84 by Mark Hurst and Kyle Powell
-
- For use with NetWare V4.0-X and -S
-
- Copyright (C) 1983, 1984 Novell, Inc.
- */
-
-
- #define LOCALBIT 0x80
- #define PERMNET 0x01
- #define TEMPNET 0x02
- #define NETBITS 0x03
-
- #define READBIT 0x01
- #define WRITEBIT 0x02
- #define OPENBIT 0x04
- #define CREATEBIT 0x08
- #define DELETEBIT 0x10
- #define OWNEDBIT 0x20
- #define SEARCHBIT 0x40
- #define MODIFYBIT 0x80
-
- #include "ctype.h"
- #include "stdio.h"
-
- #define VARPATH '^' - 'A'
-
- #define TRUE 1
- #define FALSE 0
-
- #define MAXVOLUMES 16
- #define MAXSPECS 100
- #define LISTSIZE 250
-
- #define ALLMODE 1
- #define MODMODE 2
- #define SELMODE 3
-
- extern unsigned restorerights;
-
- int imin(a, b)
- int a,b;
- {
- if (a<b) return (a);
- else return (b);
- }
-
- unsigned umin(a, b)
- unsigned a,b;
- {
- if (a<b) return (a);
- else return (b);
- }
-
- long lmin(a, b)
- long a,b;
- {
- if (a<b) return (a);
- else return (b);
- }
-
- char inline[80];
- /* buffered input of strings from console. Forces first character to
- be non-space. returns first byte of input string. If break character
- detected, then the entire string is converted to 0x03, 0x00
- */
- char getstr(t, mx)
- int mx;
- char *t;
- {
- int i, j;
- char ch;
-
- i = 0;
- while ((ch=getch()) != 0x0D && ch != 0x03 && ch != 0x1B) {
- switch(ch) {
- case 0x08: /* backspace */
- if (i) {
- i--;
- cprintf("\10 \10");
- }
- break;
- default:
- if (ch < 0x20) break;
- if (!i && ch == 0x20) break;
- if (i >= mx) {putch(7); break;}
- putch(ch);
- t[i++] = ch;
- }
- }
- if (ch == 0x0D) {
- t[i] = 0;
- return (t[0]);
- }
- /* BREAK CHARACTER or ESCAPE DETECTED, CANCEL LINE and return char */
-
- t[0] = ch;
- t[1] = 0;
- return (ch);
- }
-
- yes(q)
- char *q;
- {
- char ch;
-
- ch = 'x';
- while (ch != 'Y' && ch != 'N') {
- cprintf("%s", q);
- ch = getstr(inline, 3);
- if (ch == 3) abort();
- ch = toupper(ch);
- if (!ch) {ch = 'N'; cprintf("No");}
- cprintf("\r\n");
- }
- if (ch == 'Y') return (TRUE);
- else return (FALSE);
- }
-
- invertword(pword)
- char *pword;
- {
- char temp;
-
- temp = pword[0];
- pword[0] = pword[1];
- pword[1] = temp;
- }
-
-
- /* SECTION TO SET THE DIRECTORY PATH MAPPINGS AND MODIFY THEM
- AS THE SUBDIRECTORY STRUCTURE IS TRAVERSED
- */
-
-
- NewTemp (drive, handle, path,rhandle)
- int drive, handle,*rhandle;
- char *path;
- {
- int old, ccode, length;
- char flag, s[300], r[40];
-
- old = GetHandle (drive, &flag);
- s[1] = 0;
- s[2] = 19;
- s[3] = handle;
- s[4] = drive + 'A';
- s[5] = strlen(path);
- strcpy(&s[6], path);
- length = 4 + s[5];
- movmem(&length, s, 2);
-
- r[0] = 38;
- r[1] = 0;
- ccode = DirPath (s, r);
- if (ccode == 0xFE) LockError();
- else if (ccode) return (ccode);
- *rhandle = r[2];
- if (old != 0) {
- /*release old handle*/
- s[0] = 2;
- s[1] = 0;
- s[2] = 20;
- s[3] = old;
- DirPath (s, r);
- }
- return (0);
- }
-
-
-
- /* ROUTINE TO CREATE A NEW DIRECTORY PATH */
- static struct NewDirStruct {
- int TotalLength;
- char Request;
- char Handle;
- char AccessMask;
- char SpecLength;
- char Spec[16];
- } New = {0};
-
-
-
- BackPath (ModPath, buff)
- char *ModPath, *buff;
- {
- char *end, *ans;
- int i, len;
-
-
- SetB (0, buff, 16);
- len = strlen (ModPath);
- if (len == 0) return;
- if ((FindB ('/', ModPath, len) == -1)
- && (FindB ('\\', ModPath, len) == -1)
- && (FindB (':', ModPath, len) == -1)) {
- movmem (ModPath, buff, (len > 15) ? 15 : len);
- *ModPath = 0;
- return;
- }
-
- end = &ModPath[len - 1];
- while ((*end != '\\') && (*end != '/') && (*end != ':')) end--;
- len = strlen (&end[1]);
- movmem (&end[1], buff, (len > 15) ? 15 : len);
- if (*end == ':') end++;
- *end = 0;
- }
-
-
- MakeDir (drive,base, Path, handleptr)
- char *Path;
- int drive,base, *handleptr;
- {
- int ccode, handle, reply;
- char buff[16];
-
-
-
- ccode = NewTemp (drive, base, Path,&handle);
- if (ccode == 0) {
- *handleptr = handle;
- return (0); /*success if path exists*/
- }
- BackPath (Path, buff);
- if (buff[0] == 0) return (1); /*down to volume -- doesn't exist*/
- ccode = MakeDir (drive,base, Path, &handle);
- if (ccode != 0) return (ccode); /*problems below me*/
- New.Request = 10; /*make a new subdirectory*/
- New.Handle = handle;
- New.AccessMask = 0xFF; /*always make with all rights*/
- New.SpecLength = strlen (buff);
- movmem (buff, New.Spec, New.SpecLength);
-
-
-
-
-
-
-
- New.TotalLength = New.SpecLength + 4;
- reply = 0;
- ccode = DirPath (&New, &reply);
- if (ccode != 0) return (ccode); /*Dir Create failure*/
- ccode = NewTemp (drive, handle, buff,&handle);
- if (ccode) return (2);
- /*can't go to path--shouldn't happen*/
- *handleptr = handle;
- return (0);
- }
-
-
- getpath (handle, buffer)
- char handle;
- char *buffer;
- {
- char s[10], r[300], ccode;
- unsigned length;
-
- s[0] = 2;
- s[1] = 0;
- s[2] = 1;
- s[3] = handle;
- length = 295;
- movmem(&length, r, 2);
- ccode = DirPath(s, r);
- if (ccode == 0xFE) LockError();
- if (ccode) return (ccode);
- r[r[2] + 3] = 0;
- strcpy(buffer, &r[3]);
- return (0);
- }
-
-
-
- /* --------- STRING PRIMITIVES ----------- */
-
-
- compress(s)
- char *s;
- {
- char *c = s, ch;
-
- while (*s) if (!isspace(ch=*s++)) *c++ = ch;
- *c = '\0';
- }
-
-
- SetB (byte, buff, len)
- char byte, *buff;
- int len;
- {
- while (len-- > 0) *buff++ = byte;
- }
-
- CmpB (b1, b2, len)
- register char *b1, *b2; int len;
- {
- register int i;
-
- for (i=0; i<len; i++)
- if (*b1++ != *b2++) return (i);
- return (-1);
- }
-
- FindB (b, s, len)
- char b, *s;
- int len;
- {
- int i;
-
- for (i=0; i<len; i++) {
- if (b == s[i]) return (i);
- }
- return (-1);
- }
-
-
-
- conupper(t)
- char *t;
- {
- while (*t) {*t = toupper(*t); t++;}
- }
-
-
- LockError()
- {
- error("The Supervisor has the Directory System locked.");
- myexit(0);
- }
-
-
-
-
- checkrights(drive, pmask)
- char drive, pmask;
- {
- char ccode, mask, type;
- char s[20], r[10];
-
- s[0] = 3;
- s[1] = 0;
- s[2] = 3;
- s[3] = GetHandle(drive, &type);
- s[4] = 0; /* NULL PATH MOD SPEC, ASSUME CURRENT PATH (.) */
- r[0] = 8;
- r[1] = 0;
- ccode = DirPath (s, r);
- if (ccode == 0xFE) LockError();
- else if (ccode) return(FALSE);
- mask = r[2];
- if (mask == 0xFF) return (TRUE); /* OK TO BACK IT UP */
- if ((mask & pmask) == pmask) return (TRUE);
- else return (FALSE);
- }